package com.hivekion.quartz.taskJob;

import com.hivekion.common.Date.DateUtils;
import com.hivekion.quartz.domain.vo.JobModelVo;
import com.hivekion.quartz.service.IQuartzService;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @authot morning
 * @date 2021/8/4 9:55
 */
@Component
public class SplitTaskJob implements Job {

    private static Logger log = LoggerFactory.getLogger(SplitTaskJob.class);

//    @Autowired
//    IStatisticalParameterQuartzTaskService taskService;
    @Autowired
    IQuartzService quartzService;

    private void before() {

        log.info("******StatisticalParameterExecuteJob任务开始执行******");
    }

    @Override
    public void execute(JobExecutionContext context) {
        before();
        String name = context.getJobDetail().getKey().getName();
        if (StringUtils.isNotBlank(name)) {
            JobModelVo jobModelVo = quartzService.getInfo(name);
            if (jobModelVo != null && StringUtils.isNotBlank(jobModelVo.getData())) {
                String data = jobModelVo.getData();
                int year = DateUtils.getNowYear();
                //StatisticalParameterQuartzTaskModelVo vo = JSON.parseObject(data, StatisticalParameterQuartzTaskModelVo.class);
//                taskService.splitStatisticalTypeTask(data, year);
            }
        }
        String time =
                LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        log.info(
                "当前时间[{}],StatisticalParameterExecuteJob任务[{}]的线程名[{}]",
                time,
                name,
                Thread.currentThread().getName());
        after();
    }

    private void after() {
        log.info("******StatisticalParameterExecuteJob任务执行结束******");
    }
}
